package com.HW;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * @ClassName : T001
 * @Author : kele
 * @Date: 2023/10/22 9:09
 * @Description : 计算误码率
 */
public class TErrorCodeRate {

    public static int err = 0;
    public static int all = 0;

    public static void main(String[] args) {

        String s1 = "4Y5Z";
        String s2 = "9Y";
        handle(s1,s2);
        System.out.println(""+err+"/"+ all);

    }

    public static void handle(String str1, String str2) {

        Queue<String> stack1 = new LinkedList<>();
        Queue<String> stack2 = new LinkedList<>();

        for (String s : str1.split("(?<=\\D)(?=\\d)")) {
            stack1.add(s);
            int i = Integer.parseInt(s.split("(?<=\\d)(?=\\D)")[0]);
            all += i;
        }

        for (String s : str2.split("(?<=\\D)(?=\\d)")) {
            stack2.add(s);
        }

        while (!stack1.isEmpty()) {
            String pop1 = stack1.poll();
            String[] split = pop1.split("(?<=\\d)(?=\\D)");
            int num1 = Integer.parseInt(split[0]);
            String char1 = split[1];

            String pop2 = stack2.poll();
            String[] split2 = pop2.split("(?<=\\d)(?=\\D)");
            int num2 = Integer.parseInt(split2[0]);
            String char2 = split2[1];

            if (num1 == num2) {
                if (!char1.equals(char2)) {
                    err += num1;
                }
            } else if (num1 > num2) {

                int num = num1 - num2;
                if (!char1.equals(char2)) {
                    err += num2;
                }
                stack1.add(num + char1);
            } else {
                int num = num2 - num1;
                if (!char1.equals(char2)) {
                    err += num1;
                }
                stack2.add(num + char1);
            }
        }

    }
}
